/*
 * 
 */
package com.googlecode.ascrblr.cli.conf;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 
 * 
 */
public final class ConfigurationBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5354588398273078160L;

	private boolean valid = true;
	private String user = null;
	private String password = null;
	private boolean recursive = false;
	private boolean showHelp = false;
	private ArrayList<String> arguments = new ArrayList<String>();

	private long startTime = 0;

	/**
	 * 
	 */
	public ConfigurationBean() {
		super();
	}

	/**
	 * Gets the user.
	 * 
	 * @return the user
	 */
	public String getUser() {
		return user;
	}

	/**
	 * Sets the user.
	 * 
	 * @param user the new user
	 * 
	 * @throws IllegalArgumentException the illegal argument exception
	 */
	public void setUser(String user) throws IllegalArgumentException {
		if (isEmpty(user)) {
			throw new IllegalArgumentException(
					"setUser: User is null or empty: '" + user + "'");
		}
		this.user = user;
	}

	/**
	 * Gets the password.
	 * 
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Sets the password.
	 * 
	 * @param password the new password
	 * 
	 * @throws IllegalArgumentException the illegal argument exception
	 */
	public void setPassword(String password) throws IllegalArgumentException {
		if (isEmpty(password)) {
			throw new IllegalArgumentException(
					"setPassword: Password is null or empty: '" + password
							+ "'");
		}
		this.password = password;
	}

	/**
	 * Gets the start time.
	 * 
	 * @return the start time
	 */
	public long getStartTime() {

		return startTime;
	}

	/**
	 * Sets the start time.
	 * 
	 * @param startTime the new start time
	 * 
	 * @throws IllegalArgumentException the illegal argument exception
	 */
	public void setStartTime(long startTime) throws IllegalArgumentException {
		if (startTime < 0) {
			throw new IllegalArgumentException(
					"setStartTime: Starttime is smaller than zero: '"
							+ startTime + "'");
		}
		this.startTime = startTime;
	}

	/**
	 * @param a
	 *            String
	 * @return true if string is null or empty
	 */
	private boolean isEmpty(String string) {
		return (string == null || "".equals(string.trim()));
	}

	/**
	 * Checks if is recursive.
	 * 
	 * @return true, if is recursive
	 */
	public boolean isRecursive() {
		return recursive;
	}

	/**
	 * Sets the recursive.
	 * 
	 * @param recursive the new recursive
	 */
	public void setRecursive(boolean recursive) {
		this.recursive = recursive;
	}

	/**
	 * Gets the serial version UID.
	 * 
	 * @return the serial version UID
	 */
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	/**
	 * Sets the arguments.
	 * 
	 * @param asList the new arguments
	 * 
	 * @throws IllegalArgumentException the illegal argument exception
	 */
	public void setArguments(ArrayList<String> asList) throws IllegalArgumentException {
		if (asList == null || asList.size() <= 0) {
			throw new IllegalArgumentException(
					"setArguments: list has no elements '" + asList + "'");
		}

		this.arguments = asList;
	}

	/**
	 * Gets the arguments.
	 * 
	 * @return the arguments
	 */
	public ArrayList<String> getArguments() {
		return arguments;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return new StringBuffer().append("ConfigurationBean{").append(
				"user=" + user).append(", password=" + password).append(
				", recursive=" + recursive).append(", startTime=" + startTime)
				.append(", arguments=" + arguments).append("}").toString();
	}

	/**
	 * Checks if is show help.
	 * 
	 * @return true, if is show help
	 */
	public boolean isShowHelp() {
		return showHelp;
	}

	/**
	 * Sets the show help.
	 * 
	 * @param showHelp the new show help
	 */
	public void setShowHelp(boolean showHelp) {
		this.showHelp = showHelp;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

}
